//
//  StartReciteViewController.m
//  Learn
//
//  Created by apple on 2024/4/4.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "StartReciteViewController.h"
#import "DaTiListView.h"

#import "DaKaViewController.h"
#import "BeiDanCiRequest.h"

@interface StartReciteViewController ()
/* <#描述#> */
@property (nonatomic, strong) UIButton    * topBgView;

@property (nonatomic, strong) UIButton    * voiceBtn;

@property (nonatomic, strong) UILabel    * titleLabel;

@property (nonatomic, strong) UILabel    * subTitleLabel;
@property (nonatomic, strong) DaTiListView    * listView;


@end

@implementation StartReciteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    self.title = @"开始背单词";
    #warning ....
    self.type = KMBeiDanciType_ChoosePic;
    [self initUI];
    [self requestData];
}
- (void)setType:(KMBeiDanciType)type {
    _type = type;
    switch (type) {
        case KMBeiDanciType_Hear:
        {
            self.voiceBtn.hidden = NO;
            self.titleLabel.hidden = YES;
            self.subTitleLabel.hidden = YES;
            self.listView.isList = YES;
        }
            break;
        case KMBeiDanciType_Choose:
        {
            self.voiceBtn.hidden = YES;
            self.titleLabel.hidden = NO;
            self.subTitleLabel.hidden = YES;
            self.listView.isList = YES;
        }
            break;
        case KMBeiDanciType_ChoosePic:
        {
            self.voiceBtn.hidden = YES;
            self.titleLabel.hidden = NO;
            self.subTitleLabel.hidden = NO;
            self.listView.isList = NO;
        }
            break;
        default:
            break;
    }
}
- (void)initUI {
    [self.view addSubview:self.topBgView];
    [self.view addSubview:self.voiceBtn];
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.subTitleLabel];
    [self.view addSubview:self.listView];

}

- (UIButton *)topBgView {
    if(!_topBgView){
        _topBgView = [UIButton buttonWithType:UIButtonTypeCustom];
        _topBgView.userInteractionEnabled = NO;
        _topBgView.frame = CGRectMake(0, NavigationBarHeight, SCREEN_W, 28);
        [_topBgView setImage:[UIImage imageNamed:@"tipIcon"] forState:UIControlStateNormal];
        _topBgView.titleLabel.font  = PingFangMediumFont(12);
        
        _topBgView.backgroundColor = [COLOR_TOPIC_SELECT colorWithAlphaComponent:0.1];
        
        CGFloat leftLength = 0;
        
        NSString *str1 = @" 需新学";
        NSString *num1 = @"0";
        NSString *str2 = @"   需复习";

        NSString *num3 = @"3";

        
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@%@",str1,num1,str2,num3]];
        [attributeStr addAttribute:NSForegroundColorAttributeName
                             value:COLOR_BLACK
                             range:NSMakeRange(leftLength, str1.length)];
        leftLength += str1.length;
        
        [attributeStr addAttribute:NSForegroundColorAttributeName
                             value:COLOR_TOPIC_SELECT
                             range:NSMakeRange(leftLength, num1.length)];
        [attributeStr addAttribute:NSFontAttributeName value:PingFangMediumFont(16) range:NSMakeRange(leftLength, num1.length)];
        leftLength += num1.length;

        [attributeStr addAttribute:NSForegroundColorAttributeName
                             value:COLOR_BLACK
                             range:NSMakeRange(leftLength,str2.length )];
        leftLength += str2.length;

        [attributeStr addAttribute:NSForegroundColorAttributeName
                             value:COLOR_TOPIC_SELECT
                             range:NSMakeRange(leftLength, num3.length)];
        [attributeStr addAttribute:NSFontAttributeName value:PingFangMediumFont(16) range:NSMakeRange(leftLength, num3.length)];
        leftLength += num3.length;
        
        [_topBgView setAttributedTitle:attributeStr forState:UIControlStateNormal];
    }
    return _topBgView;
}

- (UIButton *)voiceBtn {
    if(!_voiceBtn){
        _voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _voiceBtn.frame = CGRectMake(0, 0, 46, 46);
        _voiceBtn.centerX = SCREEN_W/2;
        _voiceBtn.centerY = SCREEN_H/2 - 138;
        [_voiceBtn setImage:[UIImage imageNamed:@"voiceIcon"] forState:UIControlStateNormal];
    }
    return _voiceBtn;
}
- (UILabel *)titleLabel {
    if(!_titleLabel){
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 33)];
        _titleLabel.centerY = SCREEN_H/2 - 190;
        _titleLabel.text = @"adj.能够......的";
        _titleLabel.textColor = UIColor.blackColor;
        _titleLabel.font = PingFangMediumFont(24);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}
- (UILabel *)subTitleLabel {
    if(!_subTitleLabel){
        _subTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.titleLabel.bottom + 10, SCREEN_W, 25)];
        _subTitleLabel.text = @"[a'gau]";
        _subTitleLabel.textColor = COLOR_NOT_SELECT;
        _subTitleLabel.font = PingFangMediumFont(18);
        _subTitleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _subTitleLabel;
}


- (DaTiListView *)listView {
    if (!_listView) {
        _listView = [[DaTiListView alloc]initWithFrame:CGRectMake(0, SCREEN_H - SafeAreaBottomHeight - 225, SCREEN_W, 215)];
        WS(WeakSelf)
        _listView.cellClicked = ^{
            [WeakSelf cellClicked];
        };
        _listView.layer.borderColor = UIColor.redColor.CGColor;
        _listView.layer.borderWidth = 1;
    }
    return _listView;
}

- (void)cellClicked {
    if (self.daTiDoneBlock) {
        self.daTiDoneBlock();
    }
//    #warning 需要根据接口数据调整逻辑
//    DaKaViewController *dakaVC = [[DaKaViewController alloc]init];
//    [self.navigationController pushViewController:dakaVC animated:YES];
}


- (void)requestData {
    [BeiDanCiRequest request_getRecitingWordListWithVersionId:self.versionID ListResult:^(NSMutableArray * _Nonnull array) {
            
    }];
}
@end
